#include "commandController.h"

USART_TypeDef* COM[3] = {USART2, UART4, USART6};
que    quePltCmd[2];
extern bufferQue bufferCOM[3];

void sendCommand(command cmdx, int COMX){
    que qOut;
    uint8_t temp;
    int i;
    
    set485(COMX, TXMODE);

    qOut = makeQue(cmdx);
    for (i = 0; i < COMMAND_SIZE; ++i){
        temp = deque(&qOut);
        USART_putchar(COM[COMX], temp);
    }

    set485(COMX, RXMODE);
}

int getCommand(int COMx){
    uint8_t temp;
    while (bLen( bufferCOM[ COMx ] ) > 0) {
        temp = bDeque(&bufferCOM[ COMx ] );
        enque(&quePltCmd[COMx],temp);                
        if (temp == DELIMITERREP) {
            //SWV_puts(": GOT DELIMITERREP\n");
            return 1;
        }
    }
    return NO_REPLY;
}

